package com.stichedtogether.webapp;

import java.util.*;

import com.stichedtogether.dao.QueryExecutor;
import com.stichedtogether.dto.User;

public class UserBean {

	String username;
	String password;
	boolean isSignedIn = false;
	User user;
	
	QueryExecutor queryExecutor = new QueryExecutor();
	
	public String signIn() throws Exception{
		HashMap<String, Object> values = new HashMap<String, Object>();
		values.put("username", username);
		values.put("password", password);
		ArrayList<Object> result = queryExecutor.Read(User.class, values);
		if(result==null)
			return "Failure";
		isSignedIn = true;
		user = (User) result.get(0);
		return "Success";
	}
	
	public String createUser() throws Exception{
		HashMap<String, Object> values = new HashMap<String, Object>();
		values.put("username", username);
		values.put("password", password);
		ArrayList<Object> result = queryExecutor.Insert(User.class, values);
		if(result==null)
			return "Failure";
		isSignedIn = true;
		user = (User) result.get(0);
		return "Success";
	}
	
	public static void main(String[] args) throws Exception{
		UserBean userBean = new UserBean();
		userBean.username = "username";
		userBean.password = "password";
		System.out.println(userBean.signIn());
		User user = userBean.user;
		System.out.println(user.getUid()+", "+user.getPoints()+", "+user.getSince());
	}
	
	
}
